const { defineConfig } = require('@vue/cli-service')
const path = require('path')
const defaultSettings = require('./src/settings.js')
function resolve(dir) {
  return path.join(__dirname, dir)
}
const name = defaultSettings.title || 'YanForm-design' // page title
module.exports = defineConfig({
  publicPath: './',
  assetsDir: './',
  runtimeCompiler: true,
  lintOnSave: false,
  productionSourceMap: false,
  transpileDependencies: [
    'element-ui', 'vuedraggable',
  ],
  configureWebpack: {
    name,
    resolve: {
      alias: {
        '@': resolve('src'),
        'Yan': resolve('src/Yan-formDesign'),
      }
    }
  },
  devServer: {
    historyApiFallback: true,
    port: 8848
  },
  css: {
    loaderOptions: {
      scss: {
        /* 自动引入全局scss文件 */
        prependData: `
          @import "./src/styles/global.scss";
        `
      }
    }
  },
  chainWebpack: config => {
    /* 配置svg图标自动加载 begin */
    config.module
      .rule('svg')
      .exclude.add(resolve('src/icons'))
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
    /* 配置svg图标自动加载 end */
  },
})
